 <!--
* description: 索赔倒扣
* author: wangjuan
* createdDate: 2020-11-17
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import { exportExcel } from '@/utils/getTimeString.js'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'

export default {
  name: 'ClaimDeduction',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      data: '0',
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.claimDeductApply,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,
      titleName: '区域审核',
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          size: 'small',
          name: 'add',
          clickEvent: () => this.add(),
          text: this.$t('sys.button.add'),
          position: 'left' // 新增
        },
        {
          compKey: 'btnKey2',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          name: 'export',
          position: 'left',
          clickEvent: () => this.exportExcel111(),
          text: '导出'
        },
        {
          compKey: 'btnKey4',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '申请日期：',
              codeField: 'sendTimeStart,sendTimeEnd',
              component: () =>
                import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              // dataToObject: { timer: true, thirtyTime: true, hhmmss: true },
              format: 'yyyy-MM-dd',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '倒扣单号：',
              codeField: 'reverseCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '索赔单号：',
              codeField: 'claimCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '状态：',
              codeField: 'reverseStatus',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: vehiclePdiPriceInquirys.claimDeductSelect
              },
              oFields: 'claimStatusCode,claimStatusName',
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '车牌号：',
              codeField: 'carLicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: 'VIN码：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey7',
              labelName: '车主姓名：',
              codeField: 'custName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey8',
              labelName: '车主电话：',
              codeField: 'phone',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey9',
              labelName: '索赔分类：',
              codeField: 'claimTypeCode',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: vehiclePdiPriceInquirys.findClaimCategory
              },
              oFields: 'claimCategoryCode,claimCategoryName',
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey10',
              labelName: '活动编号：',
              codeField: 'actionCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            // {
            //   compKey: "compKey11",
            //   labelName: "门店编码：",
            //   codeField: "dlrCode",
            //   component: () => import("@/components/ve/carStockHouse"),
            //   type: "dropdownList",
            //   isMust: false,
            // },
            {
              compKey: 'compKey11',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              type: 'inputText',
              isMust: false,
              isMul: false,
              dataToObject: {
                formField: {
                  dlrCode: '',
                  dlrShortName: ''
                },
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '门店编码：',
                    codeField: 'dlrCode',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '门店名称：',
                    codeField: 'dlrName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'dlrCode',
                    label: '门店编码'
                  },
                  {
                    prop: 'dlrShortName',
                    label: '门店名称'
                  }
                ],
                returnField: {
                  prop: 'dlrCode',
                  label: '门店编码'
                },
                api: {
                  APIUrl: 'mp/e3sh/spareparts/finance/bonusOrderMakeService/queryOrgDlrCodes.do'
                }
              },
              span: 6
            }
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'subsidyId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn',
              label: '操作',
              width: 100,
              fixed: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey2',
                  labelName: '查看',
                  codeField: 'editControlBtn',
                  rowFileds: 'show:reverseStatusName-已扣款|待审核|拒绝|通过|部分扣款',
                  clickEvent: (index) => this.look(index),
                  component: () => import('@/components/org/linkButton'),
                  align: 'center'
                },
                {
                  compKey: 'propKey1',
                  labelName: '修改',
                  codeField: 'editControlBtn',
                  rowFileds: 'show:reverseStatusName-待提交',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                }
              ]
            },
            {
              prop: 'dlrCode',
              label: '门店编码'
            },
            {
              prop: 'dlrFullName',
              label: '门店名称'
            },
            {
              prop: 'reverseCode',
              label: '倒扣单号'
            },
            {
              prop: 'sendTime',
              label: '申请日期'
            },
            {
              prop: 'claimCode',
              label: '索赔单号'
            },
            {
              prop: 'claimType',
              label: '索赔分类'
            },
            {
              prop: 'reason',
              label: '倒扣原因'
            },
            {
              prop: 'reverseStatusName',
              label: '状态'
            },
            {
              prop: 'amountIncludeOldfee',
              label: '索赔金额'
            },
            {
              prop: 'reverseAmount',
              label: '应扣金额'
            },
            {
              prop: 'buckledAmount',
              label: '已扣金额'
            },
            {
              prop: 'yetAmount',
              label: '待扣金额'
            },
            {
              prop: 'creator',
              label: '申请人'
            },
            {
              prop: 'auditUser',
              label: '审核人'
            },
            {
              prop: 'auditMemo',
              label: '审核意见'
            }
          ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          sendTimeStart: '',
          sendTimeEnd: '',
          reverseCode: '',
          claimCode: '',
          reverseStatus: '',
          carLicense: '',
          vin: '',
          custName: '',
          phone: '',
          claimTypeCode: '',
          actionCode: '',
          dlrCode: '',
          choice: 1
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
    // this.data

    console.log(this.$refs.multipleTable.list, 333)
  },

  methods: {
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },
    look(index) {
      this.editPopupsState = 'look'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },
    close() {
      this.editPopupsVisible = false
      this.queryTable(1)
    },
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.claimDeductApplyExcel.APIUrl,
        vehiclePdiPriceInquirys.claimDeductApplyExcel.ServiceCode,
        '索赔倒扣申请'
      )
    }
  }
}
</script>
